<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>脚本触发器</title>

<link rel="stylesheet" href="../lib/codemirror/codemirror.css">
<link rel="stylesheet" href="../lib/codemirror/theme/darcula.css">

<style type="text/css">
html,body{
	width: 100%; height: 100%; overflow: hidden;
}
html,body,span,div{
	font-family: "Microsoft YaHei",SimSun,Arial,Helvetica,sans-serif; font-size: 12px;
	margin: 0px; padding: 0px; border: 0px;
}

div.item{
	width: calc(100% - 25px); height: 100%;
	margin-top: 10px; margin-left: 15px;
}

span.title {
	height: 16px; line-height: 16px; display: block;
}

.cm-s-darcula.CodeMirror{
	height: 120px; height: calc(100% - 38px);
}
</style>

<script type="text/javascript" src="../lib/codemirror/codemirror.js"></script>
<script type="text/javascript" src="../lib/codemirror/groovy.js"></script>
<script type="text/javascript" src="../lib/snail.common.js"></script>


</head>
<body onload="Snail.app.init()">

	<div class="item">
		<span class="title">Groovy 脚本:</span>
		<textarea name="script_content" id="script_content">
#!/snail/common/utils groovy TRIGGER_XXXXXXXXXXXXXXXXXXXX

static main(args){
	
	// 待实现
	
}		
		</textarea>
	</div>
	


<script type="text/javascript">
(function($, win, doc, undefined){

	var aesPwd = 'Xxeicq3gknHJEsZR';
	var editor = null;
	
	/**
	 * 初始化窗口
	 */
	function initWindow(){
		
		var dialog = $.getElement('div[laytype="dialog"]', -1, window.parent.document);
		
		$.setCSS(dialog, {
			width: 'calc(100% - 200px)', height: 'calc(100% - 100px)',
			top: '50px', left: '100px'
		});

		var dialogWindow = $.getElement('div[laytype="dialog"]:last-child>div:nth-child(2)', 0, window.parent.document);
		
		$.setCSS(dialogWindow, {
			height: 'calc(100% - 105px)'
		});
		
		dialogWindow = $.getElement('div[laytype="dialog"]:last-child>div:nth-child(2)>iframe', 0, window.parent.document);
		
		$.setCSS(dialogWindow, {
			height: 'calc(100% - 15px)'
		});
		
		var dialogTitle = $.getElement('div[laytype="dialog"]:last-child>div:first-child', 0, window.parent.document);
		
		$.cleanHtml(dialogTitle);
		$.appendHtml(dialogTitle, '脚本触发器');
	}

	/**
	 * 修改配置时，系统会自动把上次存储的配置值（字符串），返还给你，具体填充到form自行负责
	 */
	function initParams(){
		
		var transParams = win.dialogArguments;
		var scriptTxt = $.aes_decrypt(decodeURIComponent(transParams.configValue), aesPwd);
		
		if($.isBlank(scriptTxt)){ // 始始化脚本
			scriptTxt = '#!/snail/common/utils groovy TRIGGER_' + $.random20L() + '\r\n\r\nstatic main(args){\r\n\r\n\t// 待实现\r\n\r\n}\r\n';
		}
		
		$.setEleValue('#script_content', scriptTxt);
		
		editor = CodeMirror.fromTextArea($.getElement('#script_content'), {
			mode: 'text/x-groovy',
			theme: "darcula",
			lineNumbers: true,
			lineWrapping: true,
			indentUnit: 4,
			readOnly: !('new' == transParams.type || 'modify' == transParams.type)
		});	
	}

	$.extend('app',{
		
		init: function(){
			
			initWindow();
			
			initParams();
		}
	});

	/**
	 *	保存返回数据
	 */
	win['OK'] = function() {
	    return $.aes_encrypt((editor ? editor.getValue() : ''), aesPwd);
	}
})(Snail, window, document);
</script>
</body>
</html>